﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Model.ActiveRecord;
using System.Data;

namespace Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem.Manage
{
    public partial class DataURL : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            string dwbm = Request.QueryString["dwbm"].ToRequestString();
            string year = Request.QueryString["year"].ToRequestString();
            string month = Request.QueryString["month"].ToRequestString();
            DataSet ds = Maticsoft.DBUtility.DbHelperOra.Query("select y.bbbm, y.bbwh lrbh, y.bbmc ,y.bbzq ,t.nf,t.yf,t.tjr,t.tjsj ,t.bbzt ,t.sftgjy ,t.bbzt , t.sftgjy,y.yqsbsj ,t.shr ,t.shsj ,nvl(t.sfsh,'否') as shzt,t.bz  from bbtbqk t,code_bbbmb y where t.bbbm=y.bbbm and t.nf=" + year + " and yf = '" + month + "' and t.dwbm='" + dwbm.ToUpper() + "' order by y.pxxh asc");
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                dr["yqsbsj"] = GetReportEndTime(dr["yqsbsj"].ToString(), year, month, dr["bbzt"].ToString());
            }
            Response.Write(ds.Tables[0].ToJsonForGrid());
            Response.End();
        }



        public string GetReportEndTime(string expression, string year, string month, string bbzt)
        {
            if (!string.IsNullOrEmpty(expression))
            {
                DateTime? t = Xiaov.SmartWeb.Model.ActiveRecord.CODE_BBBMB.GetReportTimeStopTime(expression, year, month);
                if (t.HasValue)
                {
                    if (t.Value < DateTime.Now && bbzt != "已上报")
                    {
                        return "<span style=\"color:red;\">" + t.Value + "</span>";
                    }
                    else
                        return t.Value.ToString();
                }
                else
                    return "";
            }
            else
                return "";
        }     
    }
}